<?php

namespace app\common\dao\info;

use app\common\model\info\MapTaskRecord as model;
use app\common\dao\BaseDao;
use think\db\BaseQuery;

class MapTaskRecordDao extends BaseDao
{
    /**
    * 设置模型
    * @return model
    */
    protected function getModel(): string
    {
        return model::class;
    }

    public function search($where)
    {
        $query = $this->getModel()::getDB();
        $query->when(isset($where['is_export']) && $where['is_export'] !== '', function ($query)use($where){
            $query->where('is_export',$where['is_export']);
        })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query)use($where){
            $query->where('keyword',"%{$where['keyword']}%");
        })->when(isset($where['uid']) && $where['uid'] !== '', function ($query)use($where){
            $query->where('uid',$where['uid']);
        })->when(isset($where['color']) && $where['color'] !== '', function ($query)use($where){
            $query->where('color',$where['color']);
        })->when(isset($where['colorEmpty']), function ($query)use($where){
            $query->where('color','');
        })->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query)use($where){
            $query->where('is_del',$where['is_del']);
        })->when(isset($where['tags']) && $where['tags'] !== '', function ($query)use($where){
            $query->where('keyword',$where['tags']);
        })->when(isset($where['city']) && $where['city'] !== '', function ($query)use($where){
            $query->where('city',$where['city']);
        })->when(isset($where['filter']) && $where['filter'] !== '', function (BaseQuery $query)use($where){
            if($where['filter'] == 1){
                $query->where('phone','<>','');
            }else if($where['filter'] == 2){
                $query->where('phone','<>','');
                $query->whereNotLike('phone',"%-%")->whereNotLike('phone',"%(%");
            }else if($where['filter'] == 3){
                $query->whereRaw(" (`phone` like '%-%') or  (`phone` like '%(%')");
            }
        });

        return $query;
    }


}